import { defineStore } from "pinia";
import storageFn from "@/utils/storage";
// 用于持久化存储的键
const COLOR_THEME_KEY = "themeColorSession";
const FONT_SIZE_KEY = "themeFontSizeSession";

const useThemeConfigStore = defineStore("themeConfig", {
  state: () => {
    return {
      // 主题色
      themeColor:
        storageFn.getStorage("session", COLOR_THEME_KEY)?.themeColor ||
        "#005a9c",
      sysTitleColor:
        storageFn.getStorage("session", COLOR_THEME_KEY)?.sysTitleColor ||
        "#0c4785",
      // 字体大小
      themeFontSize: storageFn.getStorage("session", FONT_SIZE_KEY) || "14px",
    };
  },
  getters: {
    getColor() {
      return {
        themeColor: this.themeColor,
        sysTitleColor: this.sysTitleColor,
      };
    },
    getThemeFontSize() {
      return this.themeFontSize;
    },
  },
  actions: {
    setColor(themeColor: string, sysTitleColor: string) {
      this.themeColor = themeColor;
      this.sysTitleColor = sysTitleColor;
      storageFn.setStorage("session", COLOR_THEME_KEY, {
        themeColor: this.themeColor,
        sysTitleColor: this.sysTitleColor,
      });
    },
    setThemeFontSize(size: string) {
      this.themeFontSize = size;
      storageFn.setStorage("session", FONT_SIZE_KEY, this.themeFontSize);
    },
  },
});

export default useThemeConfigStore;
